package progma.utils;

import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;

import com.sun.xml.internal.ws.org.objectweb.asm.Type;

public class Util {

	private static AtomicInteger anonFuncCounter = new AtomicInteger(0);
	
	public static Object[] restOfArray(Object[] src, int from) {
		int retSize = src.length - from;
		Object[] ret = new Object[retSize];
		System.arraycopy(src, from, ret, 0, retSize);
		return ret;
	}
	
	public static int getFuncCounter() {
		return anonFuncCounter.incrementAndGet();
	}
	
	public static String toJavaName(String name) {
		String temp = name.replaceAll("\\+", "\\$plus");
		temp = temp.replaceAll("-", "\\$minus");
		temp = temp.replaceAll("!", "\\$excl");
		temp = temp.replaceAll("\\?", "\\$inte");
		temp = temp.replaceAll("%", "\\$perc");
		temp = temp.replaceAll("&", "\\$and");
		temp = temp.replaceAll("\\|", "\\$pipe");
		temp = temp.replaceAll("\\*", "\\$mult");
		temp = temp.replaceAll("/", "\\$slash");
		temp = temp.replaceAll(">", "\\$gt");
		temp = temp.replaceAll("<", "\\$lt");
		temp = temp.replaceAll("\\^", "\\$circ");
		temp = temp.replaceAll("#", "\\$sharp");
		temp = temp.replaceAll("=", "\\$equal");
		return temp;
	}
	
	public static String mountFunctionDesc(List<?> pars) {
		String ret = "(";
		for(int i = 0; i < pars.size(); i++) {
			ret += Type.getDescriptor(Object.class);
		}
		ret += ")" + Type.getDescriptor(Object.class);
		return ret;
	}
}
